package cn.com.zaprk.jsp;

import cn.com.zaprk.jsp.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: cn.com.zaprk.jsp
 * @ClassName: ServletDemo01
 * @Description:
 * @author: RZS
 * @date: 2021/11/27  15:37
 */
@WebServlet("/s1.do")
public class ServletDemo01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /**
         * 获取请求参数
         *
         * 将请求参数绑定到session对象中
         */
        String name = request.getParameter("name");
        String pwd = request.getParameter("pwd");
        System.out.println(name+"："+pwd);

        // 创建user对象
        User user = new User();
        user.setName(name);
        user.setPwd(pwd);

        request.getSession().setAttribute("user", user);

        request.getRequestDispatcher("/WEB-INF/main.jsp").forward(request, response);
    }
}
